package com.rceeslca.modules.cam.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rceeslca.common.utils.Result;
import com.rceeslca.modules.cam.entity.CamMajor;
import com.rceeslca.modules.cam.param.PageQueryParam;
import com.rceeslca.modules.cam.service.CamMajorService;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 专业
 */
@Api(tags="专业")
@AllArgsConstructor
@RestController
@RequestMapping("/cam/major")
public class CamMajorController {

    @Autowired
    private CamMajorService majorService;


    /**
     * 创建
     * @param major 专业
     */
    @PostMapping("create")
    public Result createMajor(@RequestBody CamMajor major) {

        majorService.createMajor(major);

        return new Result();
    }


    /**
     * 删除
     * @param major 专业
     */
    @DeleteMapping("delete")
    public Result deleteMajor(@RequestBody CamMajor major) {

        majorService.deleteMajor(major);

        return new Result();
    }


    /**
     * 更改
     * @param major 专业
     */
    @PutMapping("update")
    public Result updateMajor(@RequestBody CamMajor major) {

        majorService.updateMajor(major);

        return new Result();
    }


    /**
     * 列展示
     * @param param 条件参数
     */
    @PostMapping("getList")
    public Result<List<CamMajor>> getList(@RequestBody CamMajor param) {

        List<CamMajor> dataList = majorService.listMajor(param);

        return new Result<List<CamMajor>>().ok(dataList);
    }


    /**
     * 分页查询
     * @param param 条件参数
     */
    @PostMapping("pageList")
    public Result<IPage<CamMajor>> pageList(@RequestBody PageQueryParam<CamMajor> param) {

        Page<CamMajor> page = new Page<>(param.getPageNum(),param.getPageSize());
        IPage<CamMajor> majorIPage = majorService.pageList(page,param.getQuery());

        return new Result<IPage<CamMajor>>().ok(majorIPage);
    }

}
